package im.server;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class IMClientRunnable implements Runnable{
	
	private Socket socket;
	public IMClientRunnable(Socket socket) {
		super();
		this.socket = socket;
	}



	public Socket getSocket() {
		return socket;
	}



	public void setSocket(Socket socket) {
		this.socket = socket;
	}



	@Override
	public void run() {
		InputStream is = null;
		OutputStream os = null;
		try {
			is = socket.getInputStream();
			os = socket.getOutputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		ObjectInputStream ois;
		try {
			ois = new ObjectInputStream(is);
		
			System.out.println(ois);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		while (true){

			Scanner scanner = new Scanner(System.in);
			String msgToClient = scanner.next();
			try {
				os.write((msgToClient + "\n").getBytes());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		
	}
	
}
